function GetQueryString(name){
	     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if(r != null) return unescape(r[2]);
			return null;
	   }
	  var index = GetQueryString('Index');
	  $('.select2').select2();
	    $('#datepicker').datetimepicker({
	   	format:'YYYY-MM-DD HH:mm:ss'
     
    })
	   dataInit();
	   
	   function dataInit(){
	   	$.ajax({
	   		type:"get",
	   		url:"https://www.retux.cn/MgProductModify",
	   		async:true,
	   		data:{
	   			Id:index
	   		},
	   		success:function(data){
	   			DataView(data);
	   		}
	   	});
	   }
	   //图片显示
	 function pic_replace(dom1,dom2){
	  	var file = document.getElementById(dom1).files;
	  	var reader = new FileReader();
	  	reader.readAsDataURL(file[0]);
	  	reader.onload = function(e){
	  	  var Img = '<img class="img_sty" src="'+this.result+'" width="85px" height="100px"/>';
	  	  $('.'+dom2).html(Img)
	  	}
	  }
	   function DataView(data){
			   	var inpText = $('.new_item').find('input');
			   	for (var i = 0;i<data[0].length;i++) {
			   		if(i<5){
			   			inpText.eq(i).val(data[0][i])
			   		}	
			   		if(i>6){
			   			$('.sel').eq(i-7).val(data[0][i]).trigger('change');
			   		}
			   	}
			   	if(data[0][5].indexOf('热卖')>(-1)){
			   				$('.check').eq(1).prop('checked',true)
			   			}else{$('.check').eq(1).prop('checked',false)}
			   	if(data[0][5].indexOf('新品')>-1){
			   				$('.check').eq(0).prop('checked',true)
			   			}else{$('.check').eq(0).prop('checked',false)}
			   	if(data[0][5].indexOf('推荐')>-1){
			   				$('.check').eq(2).prop('checked',true)
			   			}else{$('.check').eq(2).prop('checked',false)}
			   	for (var i =0;i<data[2].length;i++) {
			   		$('.img').eq(i).html('<img src="'+data[2][i]+'" width="85px" height="100px" style="vertical-align: top;">')
			   	 }
			   	for (var i =0;i<data[1].length;i++) {
			   		var Inp = `<input class="form-control" type="text" value="${data[1][i][0]}" readonly="readonly"/>`;
			   		var Inp2 = `<input class="form-control" type="text" value="${data[1][i][1]}" readonly="readonly"/>`;
			   		$('.kind_box_2').append(Inp);
			   		$('.kind_box_3').append(Inp2);
			   	}
			   	$('.occcation').val(data[0][6]).trigger('change');
			   	$('.detail_pic').html('<img src="'+data[4]+'" width="85px" height="100px" style="vertical-align: top;">')
			  	$('.file_img1').html('<img src="'+data[3]+'" width="85px" height="100px" style="vertical-align: top;">')
	    }
	   $('.submit_all').click(function(){
	   	 //上架时间
	   	 var timeKind= $('input:radio[name="OnlineModel"]:checked').val();
	   	 if(timeKind=='2'){
	   	 	$('.data_pick').attr('name','DiyTime')
	   	  }
	   
	   	 
	   	 var formData = new FormData(document.getElementById('new_form3'));
	   	 formData.append('Kind',2);
	   	 formData.append('Id',index);
	   	 formData.append('Color',$(".sel").eq(0).select2('val'));
	   	 formData.append('Fabric',$(".sel").eq(1).select2('val'));
	   	 formData.append('Thickness',$(".sel").eq(2).select2('val'));
	   	 formData.append('Model',$(".sel").eq(3).select2('val'));
	   	 formData.append('Neck',$(".sel").eq(4).select2('val'));
	   	 formData.append('Ymj',$(".sel").eq(5).select2('val'));
	   	 formData.append('Season',$(".sel").eq(6).select2('val'));
	   	 formData.append('Type',$(".occcation").select2('val').join('_'))
	   	 
	   	 $.ajax({
	   	 	type:"POST",
	   	 	url:"https://www.retux.cn/MgProductModifySubmit/",
	   	 	async:true,
	   	 	data: formData,
			processData: false,
			contentType: false,
			success: function(data) {
				if(data=='success'){
					layer.msg('提交成功',{time:500},function(){
						location.reload();
					})
				}else{
					layer.msg('提交失败')
				}
			}
	   	 });
	   	 
	   })
	     
	    
	